//2009/08/27 16:56:29
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class BreakingTheCode
{
public:
    string decodingEncoding(string code, string msg)
    {
        string ret = "";
        if (isdigit(msg[0]))
        {
            for (int i=0; i<msg.size(); i+=2)
            {
                stringstream s(msg.substr(i, 2));
                int num;
                s >> num;
                ret += code[num-1];
            }
        }
        else
        {
            for (int i=0; i<msg.size(); i++)
                for (int j=0; j<code.size(); j++)
                    if (msg[i] == code[j])
                    {
                        char s[3];
						sprintf(s, "%.2d", j+1);
                        ret += s;
                        break;
                    }
        }
        return ret;
    }
};
